package com.itheima.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/*
定义交换机与队列绑定关系
 */
@Configuration
public class FanoutConfig {

    //定义一个名字为hmall.fanout的fanout交换机
    @Bean
    public FanoutExchange hmallFanoutExchange(){
//        return new FanoutExchange("hmall.fanout");
        return ExchangeBuilder.fanoutExchange("hmall.fanout").build();
    }

    //定义一个名字为hmall.queue1的队列
    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout.queue1");
    }
    //定义一个名字为hmall.queue2的队列
    @Bean
    public Queue fanoutQueue2(){
        return new Queue("fanout.queue2");
    }

    // 将fanout.queue1绑定到hmall.fanout交换机
    @Bean
    public Binding bindingFanoutQueue1(Queue fanoutQueue1,FanoutExchange hmallFanoutExchange){
        //绑定队列到交换机
        return BindingBuilder.bind(fanoutQueue1).to(hmallFanoutExchange);
    }
    //将fanout.queue2绑定到hmall.fanout交换机
    @Bean
    public Binding bindingFanoutQueue2(Queue fanoutQueue2,FanoutExchange hmallFanoutExchange){
        //绑定队列到交换机
        return BindingBuilder.bind(fanoutQueue2).to(hmallFanoutExchange);
    }
}
